package com.techsen.tsweb.sys.web.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.techsen.tsweb.core.domain.JsonResult;
import com.techsen.tsweb.core.util.sql.Pager;
import com.techsen.tsweb.sys.domain.Acl;
import com.techsen.tsweb.sys.service.AclService;

@Controller
@RequestMapping("/sys/acl")
public class AclController {

    @Resource
    private AclService aclService;
    
    /**
     * 进入访问控制管理界面
     */
    @RequestMapping
    public String index(String menuId, Model model) {
        model.addAttribute("menuId", menuId);
        return "sys/acl";
    }
    
    /**
     * 分页查询访问控制
     */
    @RequestMapping("/pager")
    public @ResponseBody Pager<Acl> pager(@RequestBody Pager<Acl> pager) {
        return this.aclService.findByPager(pager);
    }
    
    /**
     * 进入添加访问控制界面
     */
    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public String add() {
        return "sys/acl-add";
    }
    
    /**
     * 添加访问控制
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public @ResponseBody JsonResult add(Acl acl) {
        this.aclService.add(acl);
        return new JsonResult(acl);
    }
    
    /**
     * 删除访问控制
     */
    @RequestMapping("/delete")
    public @ResponseBody JsonResult delete(String id) {
        this.aclService.delete(id);
        return new JsonResult(id);
    }
    
    /**
     * 进入修改访问控制界面
     */
    @RequestMapping(value = "/update", method = RequestMethod.GET)
    public String update(String aclId, Model model) {
        Acl acl = this.aclService.get(aclId);
        model.addAttribute("acl", acl);
        return "sys/acl-update";
    }
    
    /**
     * 修改访问控制
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public @ResponseBody JsonResult update(Acl acl) {
        this.aclService.update(acl);
        return new JsonResult(acl);
    }
    
}
